package uk.co.biggroup.lotto.syndicate.dataset;

import java.io.Serializable;

public class DataLineLotto extends DataLine implements Serializable {
	
	private static final long serialVersionUID = 7526472295644776147L;
	
	public DataLineLotto(String numbers, String raffle, String lucky) {
		this.setLine(numbers, raffle, lucky);
	}

	@Override
	protected void setLine(String numbers, String raffle, String lucky) {
		this.raffle = raffle;
		this.numbers = numbers;
		this.hit = new boolean[6];
		hit[0] = false;	hit[1] = false; hit[2] = false;
		hit[3] = false;	hit[4] = false;	hit[5] = false;	
		
		String[] temp = numbers.split(DELIMITER);
		this.cnumber = new int[temp.length];
		for (int i = 0; i < temp.length; i++) {
			this.cnumber[i] = Integer.parseInt(temp[i]);
		}
		
		if(lucky.length() > 0) {
			int hitsCounter = 0;
			int hitCounter = 0;
			int counter = 0;
			String[] luckyNb = lucky.split(DELIMITER);
			for(int single : this.cnumber) {
				for (int i = 0; i < 6; i++) {
					if(Integer.parseInt(luckyNb[i]) == single) {
						hit[hitCounter] = true;
						hitsCounter++;
						counter++;
					} 
					
				}
				hitCounter++;	
			}
			if(counter >= 3) {
				int counter2 = 0;
				for(int single : this.cnumber) {
					if(Integer.parseInt(luckyNb[6]) == single) {
						hit[counter2] = true;
						hitsCounter++;
					}
					counter2++;
				}
			}
			this.hitsNo = counter + hitsCounter;
		}
	}

	@Override
	public boolean comp(String a, int lcount) {
		boolean match = false;
/*
		int size = LuckyNumbers.this.temp.length;
		for (int i = 0; i < size; i++) {
			if (lcount < 3) {
				if (a.equals(LuckyNumbers.this.temp[i]) && i <= 5) {
					this.matchCounter++;
					return true;
				}
			} else {
				if (a.equals(LuckyNumbers.this.temp[i])) {
					this.matchCounter++;
					return true;
				}
			}
		}
		*/
		return match;
	}

}
